#Requires AutoHotkey v2.0

OnlyInput := BaseOnlyInput()                                   

;窗口宽度
(A_ScreenWidth < 1500) and OnlyInput.width := 250               
(A_ScreenWidth > 2160) and OnlyInput.width := 360


;窗口样式1  白线
OnlyInput1 := Gui("+AlwaysOnTop -Caption +ToolWindow","OnlyInput1")
OnlyInput1.BackColor := "7d7d7d"
OnlyInput1.SetFont("s16", "霞鹜文楷 GB")
WinSetTransColor(000000, OnlyInput1)
OnlyInput1.AddEdit("vOnlyInputContent Background000000 cdddddd Center -E0x200 w" . OnlyInput.width . " h27 x0 y0")
;默认按钮
DefalutBtn1 := OnlyInput1.AddButton("Default w0 h0 x0 y0", "")
DefalutBtn1.OnEvent("click", (*)=>OnlyInput.guiLifeCycleDestroy())

; 窗口样式2  黑线
OnlyInput2 := Gui("+AlwaysOnTop -Caption +ToolWindow","OnlyInput2")
OnlyInput2.BackColor := "555555"
OnlyInput2.SetFont("s16", "霞鹜文楷 GB")
WinSetTransColor("ff0000", OnlyInput2)
OnlyInput2.AddEdit("vOnlyInputContent Backgroundff0000 c363636 Center -E0x200 w" . OnlyInput.width . " h27 x0 y0")
;默认按钮
DefalutBtn2 := OnlyInput2.AddButton("Default w0 h0 x0 y0", "")
DefalutBtn2.OnEvent("click", (*)=>OnlyInput.guiLifeCycleDestroy())

; 窗口样式3 闭合
OnlyInput3 := Gui("+AlwaysOnTop -Caption +ToolWindow","OnlyInput3")
OnlyInput3.BackColor := "6b6b6b"
OnlyInput3.SetFont("s16", "霞鹜文楷 GB")
WinSetTransparent(180, OnlyInput3)
OnlyInput3.AddEdit("vOnlyInputContent Background000000 cffffff Center -E0x200 w" . OnlyInput.width - 2 . " h27 x1 y1")
;默认按钮
DefalutBtn3 := OnlyInput3.AddButton("Default w0 h0 x0 y0", "")
DefalutBtn3.OnEvent("click", (*)=>OnlyInput.guiLifeCycleDestroy())


;启动窗口后的快捷键
#HotIf WinActive(OnlyInput.currentWindow.Title)  ;搜索框窗口

  #SuspendExempt true
    Tab::OnlyInput.nextRecommendWords()        ;下一个推荐词
    +Tab::OnlyInput.previousRecommendWords()        ;上一个推荐词
  #SuspendExempt false

  Space & k::OnlyInput.backHistory()               ;历史记录,后退
  Space & j::OnlyInput.forwardHistory()            ;历史记录,前进

  ; CapsLock::flashCards()                 ;翻译 和 写入obsidian的flashCards英语学习文件

  CapsLock::{                                                     ;执行自动补全              
    txt := ControlGetText("Edit1")
    tipped := (txt && (OnlyInput.getCtrText = txt) && OnlyInput.automaticCompletionProcess)
    OnlyInput.getCtrText := txt
    if (OnlyInput.getCtrText) {
      if !(tipped) {
        SetTimer(OnlyInput.automaticCompletion, 0) 
        OnlyInput._automaticCompletion()
      }
      OnlyInput.forAddressValue()
      ControlSetText("","Edit1")  ;清空搜索框
      OnlyInput.freeMemory()
    } else {
      OnlyInput.currentWindow.Hide()       ;隐藏窗口
      OnlyInput.functionIntervalContainer()
    }
  }

  Space & d::{
    ControlSetText("","Edit1")  ;清空搜索框
    OnlyInput.freeMemory()
  }

  Space & CapsLock:: {                                                ;翻译
    SetTimer(OnlyInput.automaticCompletion, 0)
    txt := OnlyInput.getCtrText := ControlGetText("Edit1")
    OnlyInput.fixedTip(Translate(txt))
  } 

  /::OnlyInput.prefixMatchRule()         ;热键 实现 前缀"//" + key 映射到 prefixMap 自动补全的功能  
  Space & /::Send "/"
  .::OnlyInput.suffixMatchRule()             ;热键 实现 后缀"." + key 映射到suffixMap 自动补全的功能
  Space & .::Send "."

  !t::{                                                               ;翻译模式
    OnlyInput.customFunction := "t"
    OnlyInput.fixedTip("Translate Custom Function")
  }
  !l::{                                                             ;localMap模式
    OnlyInput.customFunction := "l"
    OnlyInput.fixedTip("LocalMap Custom Function")
  }

#HotIf

; OnlyInput基对象
class BaseOnlyInput {
  
  width := (A_ScreenWidth/6)  ;窗口宽度
  fileDir := A_Desktop       ;遍历文件夹 默认桌面文件夹
  parameter := ""      ;Map对象里,函数的参数
  currentWindow := Gui()
  lastInputted := ""   ;输入的字符(有自动补全提示的部分)
  xpos := Round(A_ScreenWidth * 0.67)   ;显示位置x坐标
  ypos := Round(A_ScreenHeight * 0.3)  ;显示位置y坐标
  getCtrText := ""        ;监听比对
  addressValue := [] ;执行方法队列数组
  antiShakeTime := 500   ;防抖时间
  automaticCompletionProcess := 0   ;自动补全flag
  searchingHistory := []     ;历史记录
  historyIndex := 0     ;历史记录数组索引
  recommendArray := [] ;推荐数组
  recommendArrayIndex := 0 ;推荐数组索引
  automaticCompletion := ObjBindMethod(this,"_automaticCompletion")    ;自动补全settimmer需要绑定方法
  listeningInpput := ObjBindMethod(this,"_listeningInpput")            ;监听settimmer需要绑定方法
  door := 0        ;正则结果,值为2时automaticCompletion()会重新正则.
  isOneByOneCommands := 0     ;是否开启组合命令
  previousOneByOneCommands := ""     ;已检索过的组合命令
  customFunctionMap := Map(         ;自定义功能备选项,door=0时使用自定义功能.
    "l", (&content,altaFrecuencia)=>this.forLocalMap(&content,altaFrecuencia),      ;遍历LocalMap 和 遍历文件夹
    "f", (&content)=>this.loopFiles(&content),        ;遍历文件夹,默认桌面文件夹.
    "t", (&content)=>this.recommendArray.Push(Translate(content)),           ;百度翻译接口.
    "d", (&content)=>flashCards(&content)
  )
  customFunction := "l"           ;当前自定义功能,当door=0时,使用自定义功能.

  ;功能间歇容器
  functionIntervalContainer() {
    static tog := 0
    tog := !tog
    bar(&sta,fun,bool:=1,boolean:=1,func:=fun) {
      if tog {          ;onlyInput.show()后
        if (bool) {                   ;暂停执行条件
          fun()
          sta := 1
        }
      } else {                 ;onlyInput.guiLifeCycleDestroy()后
        if boolean {                    ;恢复执行条件
          if sta {                    ;show时是否执行过
            func()
          }
        }
        sta := 0
      }
    }

    static vdo := 0
    bar(&vdo,mediaPlayPause,,!this.addressValue.Length)

    static curse := 0
    bar(&curse,switchMouseMod,curseKey)
  }

  ;启动
  show() {
    if (WinActive(this.currentWindow.Title)){ 
      this.guiLifeCycleDestroy()
    } else if (WinExist(this.currentWindow.Title)) {
      WinActivate(this.currentWindow.Title)
    } else {
      this.functionIntervalContainer() 
    ; 屏幕对应位置取色
      CoordMode('pixel', 'Screen')
      brightArr := Array()
      getBright() {
        rgb := PixelGetColor(this.xpos + this.width/2 + Random(0, 60), this.ypos + 18 + Random(-10,  15))
        r := ("0x" . SubStr(rgb, 3, 2))
        g := ("0x" . SubStr(rgb, 5, 2))
        b := ("0x" . SubStr(rgb, 7, 2))
        return bright := Max(r, g, b)
      }
      loop 8 {
        brightArr.Push(getBright())
      }
      minBright := Min(brightArr*)
      maxBright := Max(brightArr*)
      if (maxBright - minBright) > 0x1E {
        this.currentWindow := OnlyInput3
      } else if ((maxBright + minBright) > 0xE1) {
        this.currentWindow := OnlyInput2
      } else {
        this.currentWindow := OnlyInput1
      }   
      this.currentWindow.show("w" . this.width . " h29 x" . this.xpos . " y" . this.ypos)
      SetTimer(this.listeningInpput, this.antiShakeTime-20)
    } 
  }

  ; tooltip显示位置
  fixedTip(content, time:=0) {
    CoordMode "ToolTip"
    SetTimer(ToolTip, 0)
    ToolTip(content, this.xpos + this.width*0.7, this.ypos + 45)
    (time) && SetTimer(ToolTip, (0 - time))
  }



  ;监听输入 
  _listeningInpput() {
    ; Critical
    if (WinActive(this.currentWindow)){ 
      edit := ControlGetText("Edit1")
      if(this.getCtrText != edit) {
        this.getCtrText := edit
        this.automaticCompletionProcess := 0
        SetTimer(this.automaticCompletion, "-" . this.antiShakeTime)
      }
    } 
  }


  ;提示词/推荐词匹配规则
  matchRules(map, str:=this.lastInputted, altaFrecuencia:=0){
    perfectMatch := 0
    num := 0 
    res := ""
    foo() {
      for k, v in map {
        if k == str {
          res := v
          this.recommendArray.InsertAt(1,k)
          perfectMatch := 1
        } else if (str = SubStr(k,1,StrLen(str)) and !perfectMatch) {
          (num) or res := v
          this.recommendArray.InsertAt(++num,k)
        } else if (InStr(k, str)) {
          (this.recommendArray.Length) or res := v
          this.recommendArray.Push(k)
        }
      }
      return res
    }
    if str {
      if altaFrecuencia {
        try {
          this.recommendArray.Push(map["_/"][str])
          res := map[this.recommendArray[1]]
        } catch {
          foo()
          (res) && map["_/"][str] := this.recommendArray[1]
        }
      } else {
        foo()
      }
    }
    return res
  }


  ;遍历 LocalMap对象
  forLocalMap(&str ,altaFrecuencia:=0){
    this.lastInputted := str
    res := this.matchRules(LocalMap,,altaFrecuencia)
    if (res) {
      this.addressValue.Push(res)
    } else {
      this.loopFiles(&str)
    }
  }

  ;遍历 文件夹
  loopFiles(&word, dir:=this.fileDir) {
    this.lastInputted := word
    pos := InStr(word,"/",,-1)               ;是否含有子文件夹
    perfectMatch := 0
    ; index := this.addressValue.Length += 1
    this.addressValue.Length := 1
    num := 0
    if pos {
      dir .=  "/" . SubStr(word,1,(pos-1)) . "/"    ;子文件夹
      word := SubStr(word,pos+1)         ;文件名
      this.lastInputted := SubStr(this.lastInputted,(pos+1))  
    } 
    loop files dir "\*" ,"DF" {
      if (A_LoopFileName = word) {
        this.addressValue[1] := A_LoopFilePath 
        this.recommendArray.InsertAt(1,A_LoopFileName . "/")
        perfectMatch := 1
      } else if (word = SubStr(A_LoopFileName,1,StrLen(word)) and !perfectMatch) {
        (num) or this.addressValue[1] := A_LoopFilePath 
        this.recommendArray.InsertAt(++num,A_LoopFileName . "/")
      } else if (InStr(A_LoopFileName, word)) {
        (this.recommendArray.Length) or (this.addressValue[1] := A_LoopFilePath)
        this.recommendArray.Push(A_LoopFileName . "/")
      }
    }
  }

  ;遍历PrefixMap
  forPrefixMap(&str,altaFrecuencia:=0){  
    Critical
    arr := StrSplit(str,"//")
    arr.RemoveAt(1)
    this.lastInputted := arr.Pop() 

    for i in arr {
      try {
        this.addressValue.Push(PrefixMap[i])
      }
    }
    if (this.door = 1 && (this.lastInputted)) {
      this.addressValue.Push(this.matchRules(PrefixMap,,altaFrecuencia))
    } else {
      forRes := this.lastInputted
    }
    return &forRes 
  }
  
  ;遍历SuffixMap
  forSuffixMap(&str,altaFrecuencia:=0){
    Critical
    strArr := Array()     ;函数方法数组
    pos := InStr(str, "/.", 0, -1)
    if pos { 
      preArr := StrSplit(SubStr(str, 1, pos-1), ".")
      strArr := StrSplit(SubStr(str, pos+2), ".")
      for i in preArr {
        this.parameter .= RTrim(i, "/") . "."
      }
      this.parameter := SubStr(this.parameter, 1, -1)
    } else {
      strArr := StrSplit(str, ".")
      this.parameter := strArr.RemoveAt(1)
    }
    (strArr.Length) && this.lastInputted := strArr.Pop()
    For i in strArr {      ;分离参数和函数方法
      try {
        this.addressValue.Push(SuffixMap[i])
      } catch {
        this.parameter .= "." i
      }
    }
    this.addressValue.Push(this.matchRules(SuffixMap,,altaFrecuencia))
  }

  ;自动补全
  _automaticCompletion(&content:=this.getCtrText, altaFrecuencia:=0) {
    Critical
    this.recommendArray := Array()
    this.recommendArrayIndex := 0
    this.automaticCompletionProcess := 1        ;判断automaticCompletion进程结束的标志
    previousLength := StrLen(this.previousOneByOneCommands)  ;之前的命令长度
    if (this.door = 2 || SubStr(content, 1, previousLength) != this.previousOneByOneCommands) {
      this.door := this.isOneByOneCommands := 0  ;之前的命令更改后,退出 One By One 模式
      this.previousOneByOneCommands := ""
      (RegExMatch(content,"^//")) && this.door += 1 
      (RegExMatch(content, "\.[^\/]+$")) && this.door += 10 
    }

    if this.isOneByOneCommands {        ;推荐上屏后为真
      this.addressValue.Length := this.isOneByOneCommands    
      this.lastInputted := subContent := SubStr(content,previousLength+1)

      switch this.door {
        case 1: this.addressValue[-1] := this.matchRules(PrefixMap,, altaFrecuencia)
        case 10: this.addressValue[-1] := this.matchRules(SuffixMap,, altaFrecuencia)
      }
    } else {
      this.lastInputted := ""
      this.parameter := ""
      this.addressValue := Array()

      if (content) {
        switch this.door {
          case 0: this.customFunctionMap[this.customFunction](&content,altaFrecuencia)
          case 1: this.forPrefixMap(&content,altaFrecuencia)
          case 10: this.forSuffixMap(&content,altaFrecuencia)
          case 11: this.forSuffixMap(this.forPrefixMap(&content),altaFrecuencia) 
        }
      }
    }
    recommendArrayToStr := ""
    For v in this.recommendArray {
      (A_Index < 25) and recommendArrayToStr .= v . "`n"     ; 限制提示词长度
    }
    this.fixedTip(recommendArrayToStr)      ;显示提示词
  }

  ;补全为输入字符
  completionRecommendWords(str := this.lastInputted) {
    BlockInput "On"
      this.isOneByOneCommands := this.addressValue.Length + 1      ;开启OneByOne模式,自动补全会用到
      if (this.recommendArray.Length) {
        ; Send("{End}" . Format("{BackSpace {1}}", StrLen(str)))    ;从recommendWord剔除已输入的字符
        ControlSetText("","Edit1")
        this.lastInputted := this.recommendArray[++this.recommendArrayIndex]
        this.getCtrText := SubStr(this.getCtrText,1,(StrLen(this.getCtrText)-StrLen(str))) . this.lastInputted
        EditPaste(this.getCtrText, "Edit1")
      }
      this.previousOneByOneCommands := this.getCtrText      ;这里是已经录入的任务,后面输入的任务=总任务-前面的任务
    BlockInput "Off"
  }

  ;选择下一个推荐词
  nextRecommendWords() {
    Critical
    SetTimer(this.automaticCompletion, 0)    
    if (this.getCtrText = ControlGetText("Edit1")) {
      if (this.automaticCompletionProcess) {
        if (!this.recommendArrayIndex && (this.recommendArray.Length) && this.lastInputted = this.recommendArray[1]) {
          this.recommendArrayIndex++   ;如果已经等于第一个匹配,则输入第二个匹配.
        } 
      } else {
        this._automaticCompletion()
      }
      if (this.recommendArrayIndex < this.recommendArray.Length) {
        this.completionRecommendWords()
        switch this.door {
          case 0:
            this.isOneByOneCommands := 0     ;这里把组合命令模式关闭.
            ControlSetText("","Edit1")
            EditPaste(this.recommendArray[this.recommendArrayIndex],"Edit1")
          case 1:
            this.addressValue[-1] := PrefixMap[this.recommendArray[this.recommendArrayIndex]]    ;将任务队列的最后任务重新赋值为当前指针下的任务
          case 10:
          case 11:
            this.addressValue[-1] := SuffixMap[this.recommendArray[this.recommendArrayIndex]]    ;将任务队列的最后任务重新赋值为当前指针下的任务
        }
      } 
    } else {
      this.getCtrText := ControlGetText("Edit1")
      this._automaticCompletion()
      this.completionRecommendWords()
    }
  }

  ;选择上一个推荐词
  previousRecommendWords() {
    Critical
    SetTimer(this.automaticCompletion, 0)
    ; txt := ControlGetText("Edit1")
    if (this.recommendArrayIndex > 1) {
      ; send("{End}" . Format("{BackSpace {1}}", StrLen(this.recommendArray[this.recommendArrayIndex])))
      ; EditPaste(this.recommendArray[--this.recommendArrayIndex],"Edit1")
      ControlSetText("","Edit1")
      len := StrLen(this.getCtrText) - StrLen(this.lastInputted)
      this.lastInputted := this.recommendArray[--this.recommendArrayIndex]
      this.getCtrText := SubStr(this.getCtrText,1,len) . this.lastInputted
      EditPaste(this.getCtrText, "Edit1")
      switch this.door {
        case 0:
          this.isOneByOneCommands := 0     ;这里把组合命令模式关闭.
          ; ControlSetText("","Edit1")
          ; EditPaste(this.recommendArray[this.recommendArrayIndex],"Edit1")
        case 1:
          this.addressValue[-1] := PrefixMap[this.recommendArray[this.recommendArrayIndex]]    ;将任务队列的最后任务重新赋值为当前指针下的任务
        case 10:
        case 11:
          this.addressValue[-1] := SuffixMap[this.recommendArray[this.recommendArrayIndex]]    ;将任务队列的最后任务重新赋值为当前指针下的任务
      }
      this.lastInputted := this.recommendArray[this.recommendArrayIndex]
      ; this.getCtrText := txt
    }
  }

  ;历史记录
  backHistory() {
    Critical
    this.door := 2
    if (this.historyIndex > 1) {
      ;为了解决使用ControlSetText后的光标被移动到行首的问题,而使用EditPaste.
      ControlSetText("", "Edit1")
      EditPaste(this.searchingHistory[--this.historyIndex], "Edit1")
    } 
  }

  forwardHistory() {
    Critical
    this.door := 2
    if (this.historyIndex < this.searchingHistory.Length) {
      ControlSetText("", "Edit1")
      EditPaste(this.searchingHistory[++this.historyIndex], "Edit1")
    } 
  }

  urlEncode(Url, RE:="[0-9A-Za-z]")
  {
    Res := ""
    Var := this.strBuf(Url, "UTF-8") ;函数在下面
      StrPut(Url, Var.Ptr, "UTF-8")
      While Code := NumGet(Var.Ptr, A_Index-1, "UChar")
      {
        Res .= (s := Chr(Code)) ~= RE ? s : Format("%{:02X}", Code)
      }
    Return Res
  }

  ; 返回包含字符串的缓冲对象.
  strBuf(str, encoding)
  {
    ; 计算所需的大小并分配缓冲.
    buf := Buffer(StrPut(str, encoding))
    ; 复制或转换字符串.
    StrPut(str, buf, encoding)
    return buf
  }

;输入//补全prefixMap里的key
  prefixMatchRule() {        
    Critical
    Send ",{BackSpace}"
    txt := ControlGetText("Edit1")   
    if (this.door < 10 || !txt) {                                  ;未开后门
      this.recommendArrayIndex := 0
      tipped := (txt && (this.getCtrText = txt) && this.automaticCompletionProcess)      ;是否提示过
      this.getCtrText := txt                                        ;避免自动补全
      if SubStr(txt, 1, StrLen(this.previousOneByOneCommands)) != this.previousOneByOneCommands {          ;命令更改后,开启正则
        this.door := 2
      }
      if this.isOneByOneCommands {
        this.lastInputted := SubStr(this.getCtrText, StrLen(this.previousOneByOneCommands)+1)
        this.addressValue.Length := this.isOneByOneCommands
        if this.lastInputted {
          if !(tipped) {
            this.recommendArray := Array()
            this.addressValue[-1] := this.matchRules(PrefixMap,, 1)                                 ;matchRules匹配高频map
          } else {
            PrefixMap["_/"][this.lastInputted] := this.recommendArray[1]                       ;推入高频
          }
        }
      } else {
        (this.getCtrText) && !(tipped) && this._automaticCompletion(, 1)                          
      }
      if (txt) {                                                   ;输入框是否有内容
        (this.lastInputted) && this.completionRecommendWords()
      } else {
        this.isOneByOneCommands := 1      ;开启OneByOne模式,自动补全会用到
      } 
      SendText "//"
      this.previousOneByOneCommands := this.getCtrText .= "//"
      this.recommendArray := Array()
      SetTimer(this.automaticCompletion, 0)
      this.automaticCompletionProcess := 1
      this.door := 1                                                 ;开启前门
    } else {                                ;后门开启后
      this.parameter .= RTrim(SubStr(txt,StrLen(this.previousOneByOneCommands)), "/")           ;参数赋值
      SendText "/."
      this.getCtrText := this.previousOneByOneCommands := txt . "/."
    }
  }

  suffixMatchRule() {         ;输入.补全sufixMap里的key
    Critical
    Send ",{BackSpace}"
    this.recommendArrayIndex := 0
    txt := ControlGetText("Edit1")
    tipped := (txt && (this.getCtrText = txt) && this.automaticCompletionProcess)                ;是否提示过
    this.getCtrText := txt                                                              ;避免自动补全
    if this.isOneByOneCommands {
      if (SubStr(txt, 1, StrLen(this.previousOneByOneCommands)) != this.previousOneByOneCommands && !tipped) {      ;命令更改后,开启正则
        this.door := 2 
        this._automaticCompletion(,1)
      }
      this.lastInputted := SubStr(this.getCtrText,StrLen(this.previousOneByOneCommands)+1)                                ;新添命令
      this.addressValue.Length := this.isOneByOneCommands                                 
      if (this.door = 10) {
        if (tipped) {                                                                     
          (this.lastInputted) && SuffixMap["_/"][this.lastInputted] := this.recommendArray[1]              ;推入高频
        } else {
          this.addressValue[-1] := this.matchRules(SuffixMap,, 1)          ;matchRules匹配高频map
        }
      }
    } else {
      if !(tipped) {
        (this.door = 2) && this._automaticCompletion(,1)
        (this.door = 0) && this.lastInputted := txt
      }
    }

    (this.addressValue.Length) || this.addressValue.Length := 1
    if (this.addressValue.Has(-1) && this.addressValue[-1]) && (this.door = 10 or this.door = 11) {      ;后门开启后
      this.completionRecommendWords()
    } else {                
      this.parameter .= (this.door = 1 or this.door = 0) ? ((this.lastInputted) || txt) : "." this.lastInputted                ;参数赋值
      this.isOneByOneCommands := this.addressValue.Length
    } 
    SendText "."
    this.previousOneByOneCommands := this.getCtrText .= "." 
    this.recommendArray := Array()
    SetTimer(this.automaticCompletion, 0)
    this.automaticCompletionProcess := 1
    this.door :=10                                                   ;开启后门
  }

  ;map参数输错后,tooltip提示,使用inputBox重新输入.
  switchParameter(map, key) {
    this.recommendArray := Array()
    res := this.matchRules(map, key)
    this.fixedTip(res, 2000)
    if !res {
      for k in map {
        str .= k "`n"
      } 
      this.fixedTip(str)
      res := this.matchRules(map, InputBox("switchParameter", "输入key", "w200 h100").Value)
      ToolTip()
    }
    return res
  }
  
  ;释放内存
  freeMemory() {
    this.isOneByOneCommands := 0                           ;退出OnebyOne模式
    this.door := 0
    this.previousOneByOneCommands := ""
    this.parameter := ""
    this.lastInputted := ""
    this.recommendArray := Array()
    this.automaticCompletionProcess := 0
    this.addressValue := Array()
  }

  ;遍历,执行任务数组中的任务
  forAddressValue() {
    Critical
    For i in this.addressValue {
      if IsSet(i) {
        if IsObject(i) {
          res := i()
          (res) && this.parameter := res
        } else {
          (i) && specificBrowserRun(i . (this.parameter && this.urlEncode(this.parameter))) ; 这里是指定和切换浏览器的函数,也可以用run()替换specificBrowserRun().
        }
      }
    } 
  } 

  ;生命周期函数 enter后启动
  guiLifeCycleDestroy() {
    Critical
    SetTimer(this.listeningInpput, 0)   ; 结束监听
    staticText := ControlGetText("Edit1")  ;获取当前输入的文本
    listened := this.getCtrText = staticText ; 这里为布尔值,判断是否监听到
    ControlSetText("","Edit1")     ;清空搜索框
    ToolTip()                      
    
    this.currentWindow.Hide()       ;隐藏窗口
    if (staticText) {
      if (this.automaticCompletionProcess and listened) {      ;判断是否需要执行automaticCompletion函数
        this.forAddressValue()
      } else {
        (this.automaticCompletionProcess) or SetTimer(this.automaticCompletion,0)    ;结束防抖,结束队列中的未执行的automaticCompletion函数
        this._automaticCompletion(&staticText, 1)                             ;立即执行automaticCompletion函数
        SetTimer(ToolTip, -2000)
        this.forAddressValue()
      }
      this.searchingHistory.Push(staticText) 
      (this.searchingHistory.Length > 10) and this.searchingHistory.RemoveAt(1)         ;限制历史记录长度为10
    }        
    this.historyIndex := this.searchingHistory.Length + 1
    this.functionIntervalContainer()              ;非必要,暂停功能
    this.freeMemory() 
  }
}  